package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain. Answer;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.service.IAnswerService;
import cn.wolfcode.trip.base.util.JasonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/answers")
public class AnswerController {

    @Autowired
    private IAnswerService AnswerService;

    /**
     * 保存提问内容
     * 参数：/
     * 资源：/qusetions
     * 动作：POST
     */
    @PostMapping
    public Object saveAnswer(Answer answer) {
        User currentUser = UserContext.getCurrentUser();
        answer.setUserId(currentUser.getId());
        //保存回答
        AnswerService.saveOrUpdate(answer);
        return new JasonResult();
    }

    @GetMapping
    public Object getAnswers(Long questionId) {
        //获取回答内容
        List<Answer> answers = AnswerService.queryAnswerContent(questionId);

        return  answers;
    }
}
